See Also

Udp Class  | Udp Members  | Overload List

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Language

Visual Basic

C#

C++

C++/CLI

Show All

buffer
A byte array to be filled with the data received.
See Also Languages PowerTCP SSL Sockets for .NET

Receive(Byte[]) Method

Dart.PowerTCP.SslSockets Namespace > Udp Class > Receive Method : Receive(Byte[]) Method

Receive a datagram.

[Visual Basic]
<DescriptionAttribute("Receive a datagram into your buffer.")> Overloads Public Function Receive( _    ByVal buffer() As Byte _ ) As Datagram
[C#]
[DescriptionAttribute("Receive a datagram into your buffer.")] public Datagram Receive(    byte[] buffer );
[C++]
[DescriptionAttribute("Receive a datagram into your buffer.")] public: Datagram* Receive(    byte[]* buffer )
[C++/CLI]
[DescriptionAttribute("Receive a datagram into your buffer.")] public: Datagram^ Receive(    bytearray<buffer>^ buffer )

Parameters

buffer
A byte array to be filled with the data received.

Return Type

A Datagram object encapsulating the datagram received.

Exceptions

ExceptionDescription
ArgumentNullExceptionbuffer is null.

Remarks

Use the Udp.Receive method to receive a datagram into buffer after first calling Open to specify a port/address to listen for datagrams. This method also returns a Datagram object encapsulating the datagram received. Buffer contains the actual datagram data (equivalent to buffer). RemoteEndPoint contains the address/port of the remote host from which the datagram was sent.

A UDP datagram provides little functionality over an IP datagram, adding a port number field which allows multiplexing on the receiving host and checksum field which provides basic error handling. Unlike TCP, UDP datagrams are sent as a unit. If Send is called 3 times to send 3 datagrams to a host, the receiving host will have to call Udp.Receive 3 times. Also, the size of each datagram sent will equal the size of each datagram received by the receiving host. In addition, since UDP is a connectionless protocol, any datagrams sent to the host are not guaranteed to be delivered. Therefore, any required error checking (outside of UDP's checksum implementation) will have to be done by the application-layer protocol.

Example

The following example demonstrates...

[Visual Basic] 

' Begin listening on the specified port and address
Udp1.Open("MyHostName", 8888)

' Send a broadcast to all hosts on the network on port 8888
Udp1.Send("hello everyone", "255.255.255.255", "8888")

' Receive the broadcast datagram.
Dim buffer(Udp1.BufferSize) As Byte
Debug.WriteLine(System.Text.Encoding.Default.GetString(buffer))

' Display data
Debug.WriteLine(d.ToString())

'* Output
'* ---------------------
'* hello everyone
'* ---------------------
'*

[C#] 


// Begin listening on the specified port and address
udp1.Open("MyHostName", 8888);

// Send a broadcast to all hosts on the network on port 8888
udp1.Send("hello everyone", "255.255.255.255", "8888");

// Receive the broadcast datagram.
byte[] buffer = new byte[udp1.BufferSize];
udp1.Receive(buffer);

// Display data
Debug.WriteLine(System.Text.Encoding.Default.GetString(buffer));

/* Output
* ---------------------
* hello everyone
* ---------------------
*/
                

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Udp Class  | Udp Members  | Overload List


Send comments on this topic.

Documentation version 1.1.2.0.

© 2008 Dart Communications.  All rights reserved.